package com.gjy.sms;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-11-17 11:27:21
 */
public class AliSms {

    private static final String keyId = "LTAI5tNET9NfHtPb6neKRwUi";
    private static final String keySecret = "AmP7Jn1fXSrxYsXjClYNz3D4FVA2my";
    private static final String endpoint = "dysmsapi.aliyuncs.com";
    private static final String aliName = "阿里云短信测试";
    private static final String aliCode = "SMS_154950909";

    public static void main(String[] args) {

        try {
            Config config = new Config()
                    .setAccessKeyId(keyId)
                    .setAccessKeySecret(keySecret);
            config.endpoint = endpoint;
            Client client = new Client(config);

            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName(aliName)
                    .setTemplateCode(aliCode)
                    .setPhoneNumbers("15855859499")
                    .setTemplateParam("{\"code\":\"" + 1234 + "\"}");

            RuntimeOptions runtime = new RuntimeOptions();
            SendSmsResponse response = client.sendSmsWithOptions(sendSmsRequest, runtime);
            /*response.getBody().getMessage() = OK
response.getBody().getCode() = OK
response.getStatusCode() = 200*/
            /*response.getBody().getMessage() = 只能向已回复授权信息的手机号发送
response.getBody().getCode() = isv.SMS_TEST_NUMBER_LIMIT
response.getStatusCode() = 200*/
            System.out.println("response.getBody().getMessage() = " + response.getBody().getMessage());
            System.out.println("response.getBody().getCode() = " + response.getBody().getCode());
            System.out.println("response.getStatusCode() = " + response.getStatusCode());

        } catch (Exception error) {
            error.printStackTrace();
        }
    }
}
